package com.caigou.modules.personal.adapter

import android.graphics.Color
import android.text.TextUtils
import android.widget.TextView
import com.caigou.comm.base.utils.ImageLoader
import com.caigou.modules.personal.R
import com.caigou.modules.personal.bean.PostItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @author #Suyghur.
 * Created on 2021/11/20
 */
class MarketItemAdapter(dataset: MutableList<PostItemBean>) :
    BaseQuickAdapter<PostItemBean, BaseViewHolder>(R.layout.item_page_market_list, dataset), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: PostItemBean) {
        holder.setText(R.id.item_page_market_tv_title, item.title)

        holder.setText(R.id.item_page_market_tv_period, item.period.toString())
        if (item.currPeriod) {
            holder.getView<TextView>(R.id.item_page_market_tv_period).setBackgroundColor(Color.parseColor("#6C99E9"))
        } else {
            holder.getView<TextView>(R.id.item_page_market_tv_period).setBackgroundColor(Color.parseColor("#B9B9B9"))
        }

        if (TextUtils.isEmpty(item.headImg)) {
            holder.setImageResource(R.id.item_page_market_iv_avatar, R.drawable.img_comm_avatar)
        } else {
            ImageLoader.loadCircle(context, item.headImg, holder.getView(R.id.item_page_market_iv_avatar))
        }

        holder.setText(R.id.item_page_market_tv_nickname, item.nickName)
        if (item.vip == 1) {
            holder.getView<TextView>(R.id.item_page_market_tv_nickname).setTextColor(Color.parseColor("#FE6880"))
        } else {
            holder.getView<TextView>(R.id.item_page_market_tv_nickname).setTextColor(Color.parseColor("#505050"))
        }

        holder.setText(R.id.item_page_market_tv_time, item.createTime)

        holder.setText(R.id.item_page_market_tv_like_num, item.nicePointCount.toString())
        holder.setText(R.id.item_page_market_tv_browse_num, item.browseCount.toString())
        holder.setText(R.id.item_page_market_tv_comment_num, item.replyCount.toString())
    }
}